home *** CD-ROM | disk | FTP | other *** search
/ Amiga Format CD 41 / Amiga Format CD41 (1999-06)(Future Publishing)(GB)[!][issue 1999-07].iso / -seriously_amiga- / programming / other / flexcat / lib / c_c_v20.sd < prev    next >
Text File  |  1999-04-19  |  5KB  |  207 lines

  1. ##stringtype C
  2. ##shortstrings
  3. /****************************************************************
  4.    This file was created automatically by `%fv'
  5.    from "%f0".
  6.  
  7.    Do NOT edit by hand!
  8. ****************************************************************/
  9.  
  10. #include <string.h>
  11.  
  12. #include <exec/memory.h>
  13. #include <libraries/iffparse.h>
  14.  
  15.  
  16. #if defined(__SASC)  ||  defined(_DCC)
  17. #include <proto/exec.h>
  18. #include <proto/dos.h>
  19. #include <proto/utility.h>
  20. #include <proto/iffparse.h>
  21. #include <proto/locale.h>
  22. #elif defined(__GNUC__)
  23. #include <inline/locale.h>
  24. #include <inline/iffparse.h>
  25. #include <inline/dos.h>
  26. #include <inline/exec.h>
  27. #include <inline/utility.h>
  28. #else
  29. #include <clib/iffparse_protos.h>
  30. #include <clib/locale_protos.h>
  31. #include <clib/dos_protos.h>
  32. #include <clib/exec_protos.h>
  33. #include <clib/utility_protos.h>
  34. #endif
  35.  
  36.  
  37.  
  38.  
  39.  
  40. static LONG %b_Version = %v;
  41. static const STRPTR %b_BuiltInLanguage = (STRPTR) %l;
  42.  
  43. struct FC_Type
  44. {   LONG    ID;
  45.     STRPTR  Str;
  46. };
  47.  
  48. const struct FC_Type _%i = { %d, %s };
  49.  
  50. static struct Catalog *%b_Catalog = NULL;
  51. static struct FC_Type *%b_OwnCatalog = NULL;
  52. static LONG %b_OwnStrings;
  53. static LONG %b_OwnBytes;
  54.  
  55. void Open%bCatalog(struct Locale *loc, STRPTR language)
  56. { LONG tag, tagarg;
  57.   extern struct Library *LocaleBase;
  58.   extern struct Library *IFFParseBase;
  59.   extern void Close%bCatalog(void);
  60.  
  61.   Close%bCatalog();  /*  Not needed if the programmer pairs Open-()
  62.              and CloseCatalog() right, but does no harm. */
  63.   if (language == NULL)
  64.   { tag = TAG_IGNORE;
  65.   }
  66.   else
  67.   { tag = OC_Language;
  68.     tagarg = (LONG) language;
  69.   }
  70.   if (LocaleBase != NULL  &&  %b_Catalog == NULL)
  71.   { %b_Catalog = OpenCatalog(loc, (STRPTR) "%b.catalog",
  72.                  OC_BuiltInLanguage, %b_BuiltInLanguage,
  73.                  tag, tagarg,
  74.                  OC_Version, %b_Version,
  75.                  TAG_DONE);
  76.   }
  77.   if (LocaleBase == NULL  &&  IFFParseBase != NULL  &&  language != NULL  &&
  78.       Stricmp(language, %b_BuiltInLanguage) != 0)
  79.   { struct IFFHandle *iffhandle;
  80.     char path[128]; /*    Enough to hold 4 path items (dos.library 3.0)  */
  81.  
  82.     if ((iffhandle = AllocIFF())  !=  NULL)
  83.     { /*  Trying to open the catalog  */
  84.       strcpy(path, "Catalogs");
  85.       AddPart((STRPTR) path, language, sizeof(path));
  86.       AddPart((STRPTR) path, (STRPTR) "%b.catalog", sizeof(path));
  87.       if ((iffhandle->iff_Stream = Open((STRPTR) path, MODE_OLDFILE))
  88.                  ==  NULL)
  89.       { strcpy(path, "Locale:Catalogs");
  90.     AddPart((STRPTR) path, language, sizeof(path));
  91.     AddPart((STRPTR) path, (STRPTR) "%b.catalog", sizeof(path));
  92.     iffhandle->iff_Stream = Open((STRPTR) path, MODE_OLDFILE);
  93.       }
  94.  
  95.       if (iffhandle->iff_Stream)
  96.       { InitIFFasDOS(iffhandle);
  97.     if (!OpenIFF(iffhandle, IFFF_READ))
  98.     { if (!PropChunk(iffhandle, MAKE_ID('C','T','L','G'),
  99.              MAKE_ID('S','T','R','S')))
  100.       { struct StoredProperty *sp;
  101.         int error;
  102.  
  103.         for (;;)
  104.         { if ((error = ParseIFF(iffhandle, IFFPARSE_STEP))
  105.              ==  IFFERR_EOC)
  106.           { continue;
  107.           }
  108.           if (error != 0)
  109.           { break;
  110.           }
  111.  
  112.           if (sp = FindProp(iffhandle, MAKE_ID('C','T','L','G'),
  113.                 MAKE_ID('S','T','R','S')))
  114.           { LONG *ptr;
  115.         LONG BytesToScan, StrLength;
  116.  
  117.         /*  First scan: Check the number of strings        */
  118.         /*  Note that this assumes that the strings are padded    */
  119.         /*  to a longword boundary!                */
  120.         %b_OwnBytes = 0;
  121.         %b_OwnStrings = 0;
  122.         BytesToScan = sp->sp_Size;
  123.         ptr = sp->sp_Data;
  124.         while (BytesToScan > 0)
  125.         { ++%b_OwnStrings;
  126.           ++ptr;              /*  Skip ID        */
  127.           StrLength = *ptr+1;          /*  NUL-Byte!        */
  128.           %b_OwnBytes += StrLength;
  129.           ptr += 1+(StrLength+3)/4;   /*  Skip Length and String*/
  130.           BytesToScan -= 8+((StrLength+3)/4)*4;
  131.         }
  132.  
  133.         /*  Marginal check: BytesToScan has to be 0!        */
  134.         if (BytesToScan == 0)
  135.         { char *cptr;
  136.           LONG i;
  137.  
  138.           if (%b_OwnCatalog = (struct FC_Type *)
  139.               AllocMem(%b_OwnStrings*sizeof(struct FC_Type)+%b_OwnBytes,
  140.                    MEMF_ANY))
  141.           { /*    Second scan: Copy the strings and their ID's    */
  142.             cptr = (char *) &%b_OwnCatalog[%b_OwnStrings];
  143.             BytesToScan = sp->sp_Size;
  144.             ptr = sp->sp_Data;
  145.             i = 0;
  146.             while (BytesToScan > 0)
  147.             { %b_OwnCatalog[i].ID = *(ptr++);
  148.               %b_OwnCatalog[i].Str = (STRPTR) cptr;
  149.               StrLength = *ptr+1;     /*  NUL-Byte!        */
  150.               ptr++;
  151.               strncpy(cptr, (char *) ptr, StrLength);
  152.                     /*  Not more, not less bytes!    */
  153.               cptr+=StrLength;
  154.               ptr += (StrLength+3)/4;
  155.               BytesToScan -= 8+((StrLength+3)/4)*4;
  156.               ++i;
  157.             }
  158.             break;
  159.           }
  160.         }
  161.           }
  162.         }
  163.       }
  164.       CloseIFF(iffhandle);
  165.     }
  166.     Close(iffhandle->iff_Stream);
  167.       }
  168.  
  169.       FreeIFF(iffhandle);
  170.     }
  171.   }
  172. }
  173.  
  174.  
  175. void Close%bCatalog(void)
  176. { if (LocaleBase != NULL)
  177.   { CloseCatalog(%b_Catalog);
  178.   }
  179.   %b_Catalog = NULL;
  180.   if (%b_OwnCatalog != NULL)
  181.   { FreeMem(%b_OwnCatalog,
  182.         %b_OwnStrings*sizeof(struct FC_Type)+%b_OwnBytes);
  183.     %b_OwnCatalog = NULL;
  184.   }
  185. }
  186.  
  187.  
  188. STRPTR Get%bString(APTR fcstr)
  189. { STRPTR defaultstr = NULL;
  190.   LONG strnum, i;
  191.  
  192.   strnum = ((struct FC_Type *) fcstr)->ID;
  193.   defaultstr = ((struct FC_Type *) fcstr)->Str;
  194.  
  195.   if (%b_Catalog == NULL)
  196.   { if (%b_OwnCatalog != NULL)
  197.     { for (i = 0;  i < %b_OwnStrings;  i++)
  198.        { if (%b_OwnCatalog[i].ID == strnum)
  199.      { return(%b_OwnCatalog[i].Str);
  200.      }
  201.        }
  202.     }
  203.     return(defaultstr);
  204.   }
  205.   return(GetCatalogStr(%b_Catalog, strnum, defaultstr));
  206. }
  207.